home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 03 Demos and Info / XMODEM.STD < prev    next >
Encoding:
Text File  |  2019-04-13  |  7.4 KB  |  181 lines

  1.  
  2.  
  3. MODEM PROTOCOL OVERVIEW  178 lines, 7.5K
  4.  
  5. 1/1/82 by Ward Christensen.  I will maintain a master copy of
  6. this.  Please pass on changes or suggestions via CBBS/Chicago
  7. at (312) 545-8086, or by voice at (312) 849-6279.
  8.  
  9. NOTE this does not include things which I am not familiar with,
  10. such as the CRC option implemented by John Mahr.
  11.  
  12. Last Rev: (none)
  13.  
  14. At the request of Rick Mallinak on behalf of the guys at
  15. Standard Oil with IBM P.C.s, as well as several previous
  16. requests, I finally decided to put my modem protocol into
  17. writing.  It had been previously formally published only in the
  18. AMRAD newsletter.
  19.  
  20.     Table of Contents
  21. 1. DEFINITIONS
  22. 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  23. 3. MESSAGE BLOCK LEVEL PROTOCOL
  24. 4. FILE LEVEL PROTOCOL
  25. 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  26. 6. PROGRAMMING TIPS.
  27.  
  28. -------- 1. DEFINITIONS.
  29. <soh>    01H
  30. <eot>    04H
  31. <ack>    05H
  32. <nak>    15H
  33. <can>   18H
  34.  
  35. -------- 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  36. Asynchronous, 8 data bits, no parity, one stop bit.
  37.  
  38.     The protocol imposes no restrictions on the contents of the
  39. data being transmitted.  No control characters are looked for
  40. in the 128-byte data messages.  Absolutely any kind of data may
  41. be sent - binary, ASCII, etc.  The protocol has not formally
  42. been adopted to a 7-bit environment for the transmission of
  43. ASCII-only (or unpacked-hex) data , although it could be simply
  44. by having both ends agree to AND the protocol-dependent data
  45. with 7F hex before validating it.  I specifically am referring
  46. to the checksum, and the block numbers and their ones-
  47. complement.
  48.     Those wishing to maintain compatibility of the CP/M file
  49. structure, i.e. to allow modemming ASCII files to or from CP/M
  50. systems should follow this data format:
  51.   * ASCII tabs used (09H); tabs set every 8.
  52.   * Lines terminated by CR/LF (0DH 0AH)
  53.   * End-of-file indicated by ^Z, 1AH.  (one or more)
  54.   * Data is variable length, i.e. should be considered a
  55.     continuous stream of data bytes, broken into 128-byte
  56.     chunks purely for the purpose of transmission. 
  57.   * A CP/M "peculiarity": If the data ends exactly on a
  58.     128-byte boundary, i.e. CR in 127, and LF in 128, a
  59.     subsequent sector containing the ^Z EOF character(s)
  60.     is optional, but is preferred.  Some utilities or
  61.     user programs still do not handle EOF without ^Zs.
  62.   * The last block sent is no different from others, i.e.
  63.     there is no "short block".  
  64.  
  65. -------- 3. MESSAGE BLOCK LEVEL PROTOCOL
  66.  Each block of the transfer looks like:
  67. <SOH><blk #><255-blk #><--128 data bytes--><cksum>
  68.     in which:
  69. <SOH>       = 01 hex
  70. <blk #>     = binary number, starts at 01 increments by 1, and
  71.               wraps 0FFH to 00H (not to 01)
  72. <255-blk #> = blk # after going thru 8080 "CMA" instr, i.e.
  73.               each bit complemented in the 8-bit block number.
  74.               Formally, this is the "ones complement".
  75. <cksum>     = the sum of the data bytes only.  Toss any carry.
  76.  
  77. -------- 4. FILE LEVEL PROTOCOL
  78.  
  79. ---- 4A. COMMON TO BOTH SENDER AND RECEIVER:
  80.  
  81.     All errors are retried 10 times.  For versions running with
  82. an operator (i.e. NOT with XMODEM), a message is typed after 10
  83. errors asking the operator whether to "retry or quit".
  84.     Some versions of the protocol use <can>, ASCII ^X, to
  85. cancel transmission.  This was never adopted as a standard, as
  86. having a single "abort" character makes the transmission
  87. susceptible to false termination due to an <ack> <nak> or <soh>
  88. being corrupted into a <can> and canceling transmission.
  89.     The protocol may be considered "receiver driven", that is,
  90. the sender need not automatically re-transmit, although it does
  91. in the current implementations.
  92.  
  93. ---- 4B. RECEIVE PROGRAM CONSIDERATIONS:
  94.     The receiver has a 10-second timeout.  It sends a <nak>
  95. every time it times out.  The receiver's first timeout, which
  96. sends a <nak>, signals the transmitter to start.  Optionally,
  97. the receiver could send a <nak> immediately, in case the sender
  98. was ready.  This would save the initial 10 second timeout. 
  99. However, the receiver MUST continue to timeout every 10 seconds
  100. in case the sender wasn't ready.
  101.     Once into a receiving a block, the receiver goes into a
  102. one-second timeout for each character and the checksum.  If the
  103. receiver wishes to <nak> a block for any reason (invalid
  104. header, timeout receiving data), it must wait for the line to
  105. clear.  See "programming tips" for ideas
  106.     Synchronizing:  If a valid block number is received, it
  107. will be: 1) the expected one, in which case everything is fine;
  108. or 2) a repeat of the previously received block.  This should
  109. be considered OK, and only indicates that the receivers <ack>
  110. got glitched, and the sender re-transmitted; 3) any other block
  111. number indicates a fatal loss of synchronization, such as the
  112. rare case of the sender getting a line-glitch that looked like
  113. an <ack>.  Abort the transmission, sending a <can>
  114.  
  115. ---- 4C. SENDING PROGRAM CONSIDERATIONS.
  116.  
  117.     While waiting for transmission to begin, the sender has
  118. only a single very long timeout, say one minute.  In the
  119. current protocol, the sender has a 10 second timeout before
  120. retrying.  I suggest NOT doing this, and letting the protocol
  121. be completely receiver-driven.  This will be compatible with
  122. existing programs.
  123.     When the sender has no more data, it sends an <eot>, and
  124. awaits an <ack>, resending the <eot> if it doesn't get one. 
  125. Again, the protocol could be receiver-driven, with the sender
  126. only having the high-level 1-minute timeout to abort.
  127.  
  128.  
  129. -------- 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  130.  
  131. Here is a sample of the data flow, sending a 3-block message.
  132. It includes the two most common line hits - a garbaged block,
  133. and an <ack> reply getting garbaged.  <xx> represents the
  134. checksum byte.
  135.  
  136. SENDER                    RECEIVER
  137.                 times out after 10 seconds,
  138.             <---        <nak>
  139. <soh> 01 FE -data- <xx>    --->
  140.             <---        <ack>
  141. <soh> 02 FD -data- xx    --->    (data gets line hit)
  142.             <---        <nak>
  143. <soh> 02 FD -data- xx    --->
  144.             <---        <ack>
  145. <soh> 03 FC -data- xx    --->
  146.    (ack gets garbaged)    <---        <ack>
  147. <soh> 03 FC -data- xx    --->        <ack>
  148. <eot>            --->
  149.             <---        <ack>
  150.  
  151. -------- 6. PROGRAMMING TIPS.
  152.  
  153. * The character-receive subroutine should be called with a
  154. parameter specifying the number of seconds to wait.  The
  155. receiver should first call it with a time of 10, then <nak> and
  156. try again, 10 times.
  157.   After receiving the <soh>, the receiver should call the
  158. character receive subroutine with a 1-second timeout, for the
  159. remainder of the message and the <cksum>.  Since they are sent
  160. as a continuous stream, timing out of this implies a serious
  161. like glitch that caused, say, 127 characters to be seen instead
  162. of 128.
  163.  
  164. * When the receiver wishes to <nak>, it should call a "PURGE"
  165. subroutine, to wait for the line to clear.  Recall the sender
  166. tosses any characters in its UART buffer immediately upon
  167. completing sending a block, to ensure no glitches were mis-
  168. interpreted.
  169.   The most common technique is for "PURGE" to call the
  170. character receive subroutine, specifying a 1-second timeout,
  171. and looping back to PURGE until a timeout occurs.  The <nak> is
  172. then sent, ensuring the other end will see it.
  173.  
  174. * You may wish to add code recommended by Jonh Mahr to your
  175. character receive routine - to set an error flag if the UART
  176. shows framing error, or overrun.  This will help catch a few
  177. more glitches - the most common of which is a hit in the high
  178. bits of the byte in two consecutive bytes.  The <cksum> comes
  179. out OK since counting in 1-byte produces the same result of
  180. adding 80H + 80H as with adding 00H + 00H.
  181.